package com.mindainfo.groundwave.server.base.config;

import com.mindainfo.groundwave.server.base.component.GlobalParams;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/11/6.
 */
@Configuration
public class RedissonConfig {

    @Resource
    private GlobalParams globalParams;

    @Bean
    public RedissonClient redisson(){
        Config config = new Config();
        String address = "redis://"
                + globalParams.getRedis().getHost()
                + ":"
                + globalParams.getRedis().getPort();
        String password = globalParams.getRedis().getPassword();
        config.useSingleServer()
                .setAddress(address)
                .setConnectTimeout(3000)
                .setPassword(password);
        RedissonClient client = Redisson.create(config);
        return client;
    }
}
